package com.woniu.bh.backstage.feign;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @version: V1.0
 * @author: Xbao
 * @className: FeignFilter
 * @packageName: com.woniu.bh.filter
 * @description:
 * @data: 2020-10-19 17:12
 */
//@Component
public class FeignInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate template) {
        ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        String token = ((HttpServletRequest)sra.getRequest()).getHeader("X-Token");
        if(token != null && !token.trim().equals("")) template.header("X-Token", token);
    }
}
